import 'package:base_lib/common/base/base_bloc_page.dart';
import 'package:base_lib/index.dart';
import 'package:base_lib/theme/theme_global.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'entity/diagnostic_result_list_entity.dart' as DiagnosticBean;
import 'bloc.dart';

///诊断结果添加
class DiagnosticSearchPage
    extends BaseBlocPage<DiagnosticSearchBloc, _DiagnosticSearchPageState> {
  DiagnosticSearchPage(Parameters parameters) : super(parameters);

  @override
  _DiagnosticSearchPageState generateThemeState() {
    return _DiagnosticSearchPageState();
  }
}

class _DiagnosticSearchPageState
    extends BaseBlocPageState<DiagnosticSearchBloc> {
  @override
  Widget buildChild(BuildContext context, MTheme theme) {
    return Scaffold(
      appBar: AppBar(
        leading: BackButton(
          onPressed: () {
            Routers.pop(context);
          },
        ),
        centerTitle: true,
        title: Text('诊断搜索'),
      ),
      body: Container(
        child: Column(
          children: [
            Container(
              margin: EdgeInsets.all(10),
              child: TextField(
                onSubmitted: (str) {
                  bloc.getList(keyStr: str);
                },
                textInputAction: TextInputAction.search,
                style: TextStyle(fontSize: 16),
                decoration: InputDecoration(
                    contentPadding: EdgeInsets.only(left: 10),
                    border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(10)),
                    hintText: '请输入诊断名称',
                    hintStyle: TextStyle(fontSize: 12)),
              ),
            ),
            Expanded(
              child: StreamBuilder(
                stream: bloc.listSubject,
                builder: (context,
                    AsyncSnapshot<List<DiagnosticBean.Data>> snapshot) {
                  return snapshot.hasData
                      ? ListView.builder(
                          itemCount: snapshot.data.length,
                          itemBuilder: (context, pos) {
                            DiagnosticBean.Data item = snapshot.data[pos];
                            return Container(
                              padding: EdgeInsets.symmetric(vertical: 5),
                              decoration: BoxDecoration(
                                  border: Border(
                                      bottom:
                                          BorderSide(color: Colors.grey[300]))),
                              child: Row(
                                children: [
                                  10.hGapDp,
                                  Expanded(
                                    child: Text(
                                      item.hisParaValue,
                                      style: TextStyle(
                                          fontSize: 16,
                                          color: Colors.black,
                                          fontWeight: FontWeight.bold),
                                    ),
                                  ),
                                  10.hGapDp,
                                  IconButton(
                                    onPressed: () {
                                      Routers.pop(context, item);
                                    },
                                    icon: Icon(
                                      Icons.add_circle_outline,
                                      color: theme.themeColor.themeColor,
                                    ),
                                  ),
                                  10.hGapDp,
                                ],
                              ),
                            );
                          })
                      : buildLoadingIndicator();
                },
              ),
            ),
          ],
        ),
      ),
    );
  }

  @override
  DiagnosticSearchBloc generateBloc() {
    return DiagnosticSearchBloc();
  }
}
